﻿package com.calefk.core {
	
    import com.calefk.util.Collection;
	import com.calefk.util.Fade;
	import com.calefk.util.Iterator;
	import flash.display.MovieClip;
	import flash.events.KeyboardEvent;
    /**
     * Clase que heredan todos las paginas creadas en el Mod,
     * administra popups y sus eventos del teclado
     * 
     */
	public class Page extends EntitySimple {
		
		public var mPopups:List;
		protected var mFade:Fade;
		
		public function Page(canvas:MovieClip , nameClip:String = null,
				x:Number = 0, y:Number = 0) {
			super(canvas , nameClip , x , y);
			mPopups = new List();
		}
        /**
         * Metodo que es llamado luego del "gotoPage", se puede enviar un objeto
         * @param param cualquier objeto
         */
        public function init(param:* = null):void {
        }
		
		public function addPopup(popup:Page):void {
			mPopups.add(popup);
		}
		
		override public function update(dt:int):void {
            mPopups.update(dt);
		}
		
		public function onKeyDown(e:KeyboardEvent):void {
            var it:Iterator = mPopups.iterator();
            while (it.hasNext()) {
                var popup:Page = it.next() as Page;
                popup.onKeyDown(e);
            }
		}
		
		public function onKeyUp(e:KeyboardEvent):void {
            var it:Iterator = mPopups.iterator();
            while (it.hasNext()) {
                var popup:Page = it.next() as Page;
                popup.onKeyUp(e);
            }
		}
		
		override public function clean():void {
            mPopups.cleanElements();
            mPopups = null;
			super.clean();
		}
	}

}